package com.github.cyf.scheduled;

import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @author chenyifan
 * @create 2024-03-17 20:12
 */
@Slf4j
@Component
//@Async
public class ScheduledTask {

    @Scheduled(cron="0/3 * *  * * ? ")
    public void task1() throws InterruptedException {
        Thread.sleep(6000);
        log.info("每 3s 执行一次定时任务");
    }

    @Scheduled(cron="0/1 * * * * ? ")
    public void task2(){
        log.info("每 1s 执行一次定时任务");
    }

    @Scheduled(fixedDelay = 2000)
    public void task3() throws InterruptedException {
        Thread.sleep(4000);
        log.info("每 2s 执行一次定时任务");
    }

    @Scheduled(fixedRate = 2000)
    public void task4() throws InterruptedException {
        Thread.sleep(4000);
        log.info("每 2s 执行一次定时任务");
    }
}
